/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utt.edu.com.Controlador;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author Ceci
 */
public class CtrlConexion {
    private String DRIVER = null;
    private String URL = null;
    private Connection conexion = null;

    public CtrlConexion() {
        this.Configurar();

    }

    private void Configurar() {
        this.DRIVER = "sun.jdbc.odbc.jdbcOdbcDriver";
        this.URL = "jdbc:Odbc:odbcNombreBase";
    }

    public Connection getConexion() {
        try {
            if (this.conexion == null) {
                Class.forName(this.DRIVER);
                this.conexion = DriverManager.getConnection(URL);
                this.conexion.setAutoCommit(false);
            }
            return this.conexion;

        } catch (Exception ex) {
            System.out.println(ex);
            return null;
        } finally {
            System.gc();
        }
    }

    public void cerrarConexion() {
        try {
            if (this.conexion != null) {
                this.conexion.close();


            } else {
                this.conexion = null;


            }

        } catch (Exception ex) {
            System.out.println(ex);
        } finally {
            System.gc();
        }
    }
}
